package cn.com.pc.content.domain.risk;

import cn.com.pc.content.domain.content.Content;
import cn.com.pc.content.domain.content.ContentType;
import cn.com.pc.content.domain.article.Article;
import cn.com.pc.content.util.HttpClientUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@Component
@Slf4j
public class CensorPlatformRiskAuditor implements RiskAuditor {

    private String censorIntfUrl;
    private String APP;
    private String TYPE_ID;


    @Override
    public int audit(Risk risk) {
        Content content = getContent(risk);
        Map<String, String> params = new HashMap<String, String>();
        params.put("site", content.getSite().getName());
        params.put("app", APP);
        params.put("typeId", TYPE_ID);
        params.put("isNew", "1");
        params.put("uri", uri(content, risk.getContentType()));
        params.put("version", System.currentTimeMillis()+"");
        params.put("title", content.getTitle());
        params.put("content", buildContentString(content, risk.getContentType()));
        params.put("userId", content.getAuthor().getPassportId()+"");
        params.put("userName", content.getAuthor().getFullName());
        params.put("ip", content.getIp());
        params.put("isHtml", "1");
        try {
            HttpClientUtils.httpPost(censorIntfUrl, "GBK", "GBK", true, null, params);
        } catch (IOException e) {
            log.error("内容推送审核平台异常，ID："+content.getId()+",error:");
            e.printStackTrace();
        }
        return 0;
    }

    private String buildContentString(Content content, ContentType contentType) {
        //TODO build content string for censorplatform, plain html text
        return "";
    }

    private Content getContent(Risk risk) {
        //TODO find content by risk
        return new Article();
    }

    private String uri(Content content, ContentType contentType){
        //TODO build uri of content
        return "";
    }
}
